using System;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.TrainingRecord;

namespace TrainingManagement.api.Models.BusinessLogic.TrainingRecord
{
    public class TrainingRecordUpdateOperation : BusinessOperation<BusinessObjects.TrainingRecord, bool>
    {
        readonly TrainingRecordUpdateDataSource _trainingRecordUpdate = new TrainingRecordUpdateDataSource();

        public override bool Run(BusinessObjects.TrainingRecord input)
        {
            input.SkillId = input.Skill.SkillId;
            if (_trainingRecordUpdate.Execute(input))
                return true;
            throw new Exception("Training record failed to update.");
        }
    }
}